package com.zhx.beancopyutils.mapper;

import com.zhx.beancopyutils.bean.UserVO;
import com.zhx.beancopyutils.bean.UserVO1;
import com.zhx.beancopyutils.bean.dto.UserDTO;
import com.zhx.beancopyutils.mapper.base.BaseMapper;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;


/**
 * @author zhang-rongyao
 * @version V1.0
 * @Package com.zhx.beancopyutils.mapper
 * @date 2021/6/21 10:40
 */

// spring方式加载
@Mapper(componentModel = "spring")
public interface UserMapper extends BaseMapper<UserDTO, UserVO> {

    UserMapper INSTANCE = Mappers.getMapper(UserMapper.class);

    /**
     * 字段数量类型数量相同，利用工具BeanUtils也可以实现类似效果
     * @param source
     * @return
     */
    @Override
    @Mappings({
            @Mapping(source = "id",target = "id"),
            @Mapping(source = "name",target = "name"),
            //日期转化
            @Mapping(source = "createTime",target = "create_Time",dateFormat = "yyyyMMdd"),
            @Mapping(source = "updateTime",target = "update_Time"),
            @Mapping(target = "xxx",ignore = true)
    })
    UserVO to(UserDTO source);

    @Override
    UserDTO from(UserVO var1);
}
